/*
 * 9.8.cpp 1011_poj
 *
 *  Created on: 2012-5-21
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define MAX 65

int sticks[MAX];
bool used[MAX];
int n;

int compare(const void *a, const void *b) {
	return (*((int *)b) - *((int *)a));
}

bool fn (int unusedSticks, int left, int len) {
	if (unusedSticks == 0 && left == 0) return true;
	if (unusedSticks == 0 && left > 0) return false;
	if (left == 0) left = len;
	for (int i=0; i<n; i++) {
		if (!used[i] && sticks[i] <= left) {
			used[i] = true;
			if (fn (unusedSticks-1, left-sticks[i], len)) return true;
			used[i] = false;
			if (sticks[i] == left || left == len) break; //key step
		}
	}
	return false;
}

int main (void) {
	while (true) {
		scanf("%d", &n);
		if (n==0) break;
		int sum = 0;
		for (int i=0; i<n; i++) {
			scanf("%d", &sticks[i]);
			used[i] = false;
			sum += sticks[i];
		}
		qsort(sticks, n, sizeof(int), compare);
		int len;
		for (len=sticks[0]; len<=sum; len++) {
			if (sum%len == 0)
				if (fn (n, len, len))
					break;
		}
		printf("%d\n", len);
	}
	return 0;
}
